<!--轨迹图GPS定位
 * @Author 杨宇翔
 * @Date 20220713 13:49:03
 * @LastEditors 杨宇翔
 * @LastEditTime 20220713 13:49:03
-->
<template>
    <div class="trace-plot" v-show="UsageComponent.Default.ShowTracePlot.value">
        <div class="container">
            <div class="header">
                <span>运动轨迹</span>
                <span class="material-icons" @click="UsageComponent.Default.ShowTracePlot.value = false">cancel</span>
            </div>
            <div class="chart" ref="container"></div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ProtocolComponent, UsageComponent } from './InertialNavigationComponent';
import { EChartOption, EChartsType, init } from 'echarts';
import { computed, onMounted, onUnmounted, ref, Ref, watch } from 'vue';

const data = computed(() => ProtocolComponent.Default.TracePlotPoints.map(point => [Math.trunc(point.Longitude - ProtocolComponent.Default.TracePlotPoints[0].Longitude), Math.trunc(point.Latitude - ProtocolComponent.Default.TracePlotPoints[0].Latitude)]));
watch(data, value => {
    chart?.setOption({
        series: [
            {
                name: 'Data',
                type: 'line',
                xAxisIndex: 2,
                yAxisIndex: 2,
                data: value
            }
        ]
    });
});

const container: Ref<HTMLDivElement | null> = ref(null);
let chart: EChartsType | null = null;

onMounted(async () => {
    chart = init(container.value!, 'dark');
    const option = {
        backgroundColor: 'transparent',
        tooltip: {
            formatter: '({c})'
        },
        dataZoom: [
            {
                type: 'inside',
                xAxisIndex: [0, 1, 2],
                yAxisIndex: [0, 1, 2],
                throttle: 0
            }
        ],
        grid: [
            {
                left: '5%',
                top: '5%',
                right: '5%',
                bottom: '5%'
            },
            {
                left: '5%',
                top: '5%',
                right: '5%',
                bottom: '5%'
            },
            {
                left: '5%',
                top: '5%',
                right: '5%',
                bottom: '5%'
            }
        ],
        xAxis: [
            {
                gridIndex: 0,
                // min: -10 * 1e-7,
                // max: 10 * 1e-7,
                // interval: 1e-7,
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: false
                }
            },
            {
                gridIndex: 1,
                name: 'X',
                // min: -10 * 1e-7,
                // max: 10 * 1e-7,
                // interval: 1e-7,
                axisLine: {
                    symbol: ['none', 'arrow']
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: false
                }
            },
            {
                gridIndex: 2,
                // min: -10 * 1e-7,
                // max: 10 * 1e-7,
                // interval: 1e-7,
                axisTick: {
                    show: false
                },
                axisLine: {
                    onZero: false,
                    lineStyle: {
                        width: 2,
                        color: '#2A2E45'
                    }
                }
            }
        ],
        yAxis: [
            {
                gridIndex: 0,
                // min: -5 * 1e-7,
                // max: 5 * 1e-7,
                // interval: 1e-7,
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: false
                }
            },
            {
                gridIndex: 1,
                name: 'Y',
                // min: -5 * 1e-7,
                // max: 5 * 1e-7,
                // interval: 1e-7,
                axisLine: {
                    symbol: ['none', 'arrow']
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    show: false
                }
            },
            {
                gridIndex: 2,
                // min: -5 * 1e-7,
                // max: 5 * 1e-7,
                // interval: 1e-7,
                axisTick: {
                    show: false
                },
                axisLine: {
                    onZero: false,
                    lineStyle: {
                        width: 2,
                        color: '#2A2E45'
                    }
                }
            }
        ],
        series: [
            {
                name: 'Grid',
                type: 'line',
                xAxisIndex: 0,
                yAxisIndex: 0
            },
            {
                name: 'Axis',
                type: 'line',
                xAxisIndex: 1,
                yAxisIndex: 1
            },
            {
                name: 'Data',
                type: 'line',
                xAxisIndex: 2,
                yAxisIndex: 2,
                data: []
            }
        ]
    };

    chart.setOption(option as EChartOption);
});

onUnmounted(() => {
    chart?.dispose();
});
</script>

<style scoped>
.trace-plot {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;

    backdrop-filter: blur(1rem);
}

.chart {
    width: 124rem;
    height: 62rem;
    border-radius: 1rem;

    margin-bottom: 4rem;
}

.container {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);

    width: 132rem;
    height: 84rem;

    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;

    gap: 2rem;

    border-radius: 2rem;
    border: solid 0.6rem transparent;
    background-image: linear-gradient(#131620, #131620),
        linear-gradient(90deg, #218cde, #807de1);
    background-origin: border-box;
    background-clip: content-box, border-box;
}

.header {
    width: 100%;

    padding: 2rem;

    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header>span:first-of-type {
    color: white;
    font-size: 2.4rem;
    font-weight: 500;
}

.header>.material-icons {
    color: #81859C;
    font-size: 3.6rem;
}

.search {
    width: 100%;

    padding-left: 4rem;

    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 2rem;
}

.search>span {
    color: #81859C;
    font-size: 1.8rem;

    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

.search>input {
    margin: 0;
    padding: 1.5rem;

    width: 20rem;
    height: 3.6rem;
    color: #B1B1D4;
    font-size: 1.8rem;
    line-height: 3.6rem;
    text-align: center;

    border: solid 0.1rem #36384B;
}

.search>input:focus {
    border: solid 0.1rem;
    border-image: linear-gradient(90deg, rgba(128, 125, 225, 1), rgba(33, 140, 222, 1)) 1 1;
}

.search>button {
    width: 10rem;
    height: 4rem;

    border-radius: 0.6rem;
    background: linear-gradient(180deg, #807DE1 0%, #218CDE 100%);
}

.search>button>span {
    color: white;
    font-size: 1.8rem;
}
</style>